<template>
  <div class="login">
    <van-form @submit="onSubmit">
  <van-cell-group inset>
    <van-field
      v-model="username"
      name="用户名"
      label="用户名"
      placeholder="用户名"
      :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
      v-model="password"
      type="password"
      name="密码"
      label="密码"
      placeholder="密码"
      :rules="[{ required: true, message: '请填写密码' }]"
    />
  </van-cell-group>
  <div style="margin: 16px;">
    <van-button round block type="primary" native-type="submit">
      提交
    </van-button>
  </div>
</van-form>
  </div>
</template>

<script setup lang="ts">
import {ref,reactive} from "vue"
import {loginAPI} from "@/api/loginApi"
import {getGoodsListAPI} from "@/api/goodsApi"
import { useRouter } from "vue-router";
import { showToast } from 'vant';
let $router = useRouter()
let username = ref('')
let password = ref('')
const onSubmit =()=>{
  if(username.value == 'admin'&& password.value=='123456'){
    loginAPI({}).then((res:any)=>{
      if(res.code == 200){

        localStorage.setItem('token',res.token)
        localStorage.setItem('login',username.value)
        $router.push('/home')
      }
  })
  }
}
</script>

<style scoped>
.login {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202003%2F17%2F20200317213735_jnPHM.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1693392069&t=f022ab3d925053eee256cd852191790b");
  background-repeat: no-repeat;
  background-size: cover;
}
</style>